#!/usr/bin/env sh

# the scripting-addition must be loaded manually if
# you are running yabai on macOS Big Sur. Uncomment
# the following line to have the injection performed
# when the config is executed during startup.
#
# for this to work you must configure sudo such that
# it will be able to run the command without password
#
# see this wiki page for information:
#  - https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)
#
#sudo yabai --load-sa
#yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"

#set -x

# initialization
#arch -arm64e sudo yabai --load-sa
#sudo yabai --load-sa
#yabai -m signal --add event=dock_did_restart action="arch -arm64e sudo yabai --load-sa"

source ~/.config/yabai/scripts/initialization.sh

# ====
# Signals
# ====

# Initialize the temp folder when adding or removing displays
yabai -m signal --add event=display_added action="~/.config/yabai/scripts/initialization.sh"
yabai -m signal --add event=display_removed action="~/.config/yabai/scripts/initialization.sh"

# Auto focus on window after switching space.
yabai -m signal --add event=space_changed action='~/.config/yabai/scripts/active_window_when_change_space.sh'


# global settings 全局配置
## 设置鼠标是否跟随当前活动窗口 默认 off: 关闭 on: 开启
yabai -m config mouse_follows_focus          off
## 焦点跟随鼠标 默认off: 关闭  autoraise:自动提升 autofocus: 自动对焦
yabai -m config focus_follows_mouse          autofocus
## 默认拆分规则
yabai -m config window_origin_display        default
yabai -m config window_placement             second_child
## 浮动窗口在最顶部
yabai -m config window_topmost               off
## 窗口阴影 on：打开； off 关闭；float： 只显示浮动窗口的阴影
yabai -m config window_shadow                on

## 窗口透明度设置
yabai -m config window_opacity               on
## 配置活动窗口不透明度
yabai -m config window_opacity_duration      0.0
yabai -m config active_window_opacity        1.0
yabai -m config normal_window_opacity        0.90

## 窗口线框设置
yabai -m config window_border                off
yabai -m config window_border_width          6
yabai -m config active_window_border_color   0xff775759
yabai -m config normal_window_border_color   0xff555555
yabai -m config insert_feedback_color        0xffd75f5f

## 自动平衡所有窗口始终占据相同的空间
yabai -m config auto_balance                 off
# 如果禁用自动平衡，此项属性定义的是新窗口占用的空间量。0.5意为旧窗口占用50%
yabai -m config split_ratio                  0.50

# 鼠标修饰键 意思就是按着这个键就可以使用鼠标单独修改窗口大小了
yabai -m config mouse_modifier               fn
## fn + 左键 移动
yabai -m config mouse_action1                move
## fn + 右键 
yabai -m config mouse_action2                resize
## fn 切换活动
yabai -m config mouse_drop_action            swap

# 在主显示器上的每个空间顶部添加 20 填充 底部添加 0 填充
# yabai -m config external_bar main:20:0
# 在所有显示器上的每个空间顶部添加 0 填充 底部添加 5 填充
# yabai -m config external_bar all:0:5

# --- general space settings -----------------------------

## 窗口布局 bsp: 平铺 float: 浮动
## 为了方便其他人用电脑默认是 float,用时再切换到 bsp
#yabai -m config layout                       bsp
yabai -m config layout                       float
## 窗口间距设置
yabai -m config top_padding                  2
yabai -m config bottom_padding               2
yabai -m config left_padding                 2
yabai -m config right_padding                2
yabai -m config window_gap                   06

# -- rule settings ---------------------------------------
# 规则

## 打开系统偏好设置，不使用平铺模式
yabai -m rule --add app="^系统偏好设置$" manage=off
yabai -m rule --add app="^提醒事项$" manage=off
yabai -m rule --add app="^关于本机$" manage=off

#yabai -m rule --add app="访达$" manage=off
#yabai -m rule --add app="终端$" manage=off
#yabai -m rule --add app="dev-sidecar$" manage=off
yabai -m rule --add app="Feem$" manage=off
yabai -m rule --add app="微信$" manage=off

otherApp='^(坚果云|Calendar|日历|System Preferences|系统偏好设置|Mail|微信|WeChatc|QQ|网易云音乐|Alfred Preferences|Tencent Lemon|企业微信)$'
yabai -m rule --add app="${otherApp}" manage=off


echo "yabai configuration loaded.."